﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.ModelConfiguration;
using System.Reflection;
using System.ComponentModel.DataAnnotations;

namespace BugTracker.Models
{
    public class Bug_db : DbContext
    {
        public Bug_db()
            : base("Bug_db")
        {
            System.Data.Entity.Database.SetInitializer<Bug_db>(null);
        }

        public DbSet<Issue> Issues { get; set; }
        public DbSet<Status> Status { get; set; }
        public DbSet<Project> Projects { get; set; }
        public DbSet<Relationship> Relationships { get; set; }
        public DbSet<Report> Reports { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<Session> Sessions { get; set; }
        public DbSet<Severity> Severities { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Task> Tasks { get; set; }
        public DbSet<ErrorLog> ErrorLogs { get; set; }

        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Entity<Issue>().ToTable("dbo.Issue");
            modelBuilder.Entity<Issue>().Property(i => i.issue_idPK);

            modelBuilder.Entity<Project>().ToTable("dbo.Project");
            modelBuilder.Entity<Project>().Property(p => p.project_idPK);

            modelBuilder.Entity<Relationship>().ToTable("dbo.Relationship");
            modelBuilder.Entity<Relationship>().Property(R => R.relation_idPK);

            modelBuilder.Entity<Report>().ToTable("dbo.Report");
            modelBuilder.Entity<Report>().Property(r => r.report_idPK);

            modelBuilder.Entity<Role>().ToTable("dbo.Role");
            modelBuilder.Entity<Role>().Property(ro => ro.role_idPK);

            modelBuilder.Entity<Session>().ToTable("dbo.Session");
            modelBuilder.Entity<Session>().Property(s => s.session_idPK);

            modelBuilder.Entity<Severity>().ToTable("dbo.Severity");
            modelBuilder.Entity<Severity>().Property(S => S.severity_idPK);

            modelBuilder.Entity<User>().ToTable("dbo.User");
            modelBuilder.Entity<User>().Property(u => u.user_idPK);

            modelBuilder.Entity<Status>().ToTable("dbo.Status");
            modelBuilder.Entity<Status>().Property(u => u.status_id);

            modelBuilder.Entity<Task>().ToTable("dbo.Task");
            modelBuilder.Entity<Task>().Property(t => t.task_assignID);

            modelBuilder.Entity<ErrorLog>().ToTable("dbo.ErrorLog");
            modelBuilder.Entity<ErrorLog>().Property(e => e.erroridPK);

        }

    }
}